SAS字符型函数 | 您所在的位置:网站首页 › sas strip函数 › SAS字符型函数 |
528866wmYSJ* ```sql data compress_1; x1=" 1 2 a 3"; x2="Abacabbad"; x3="134-7596-5241"; x4="123***14567"; y1=compress(x1," "); y2=compress(x2,"Ab");/*消除的是A 或b不是且的关系*/ y3=compress(x3,"0123456789","k"); /*消除除了数字外的所有其它字符*/ y4=compress(x4,"0123456789","k"); run; 在这里插入代码片`在这里插入代码片` ```sql data compress_1; x1=" 1 2 a 3"; x2="Abacabbad"; x3="134-7596-5241"; x4="123***14567"; y1=compress(x1," "); y2=compress(x2,"Ab");/*消除的是A 或b不是且的关系*/ y3=compress(x3,"0123456789","k"); y4=compress(x4,"0123456789","k"); y5=compress(x1);/*什么都不写,默认是清楚空格*/ run; data compress_mob; length Mob_Phe$ 14; input Mob_Phe$ @@; Cards; 13915625877 013145672561 134-7596-5241 1364524124 01045125421 ; run; /*要消除不是数字的其它字符*/ data mob1; set compress_mob; if length(compress(Mob_Phe,"0123456789","k"))=11 then do; mob_phone=substr(compress(Mob_Phe,"0123456789","k"),1,11); if substr(compress(Mob_Phe),1,3) in("130","131","132","133","150","151","152","153") then do; flag="联通";output;END; else if substr(compress(Mob_Phe),1,3) in("134","135","136","137","138","139", "154","155","156","157","158","159") then do; flag="移动";output;END; end; else if length(compress(Mob_Phe,"0123456789","k"))=12 and substr(compress(Mob_Phe),1,1)="0" then do; mob_phone=substr(compress(Mob_Phe,"0123456789","k"),2,11); if substr(compress(Mob_Phe),2,3) in("130","131","132","133","150","151","152","153") then do; flag="联通";output;END; else if substr(compress(Mob_Phe),2,3) in("134","135","136","137","138","139", "154","155","156","157","158","159") then do; flag="移动";output;END; end; run;
发现对X没有规定格式,输出的是数字 x=abcd e y=bcd e y2=b z=cd e /*tranwrd替代字符,tranwrd(str,需要替代的字符,替换成哪个字符)*/ data test4; x="abcdaba"; x1=compress(x,"ab"); y=tranwrd(x,"ab","k"); z=tranwrd(x,"ab",""); lz=length(z); z1=tranwrd(x,"ab"," "); lz1=length(z1); m=compress(z); m1=compress(z1); put x=; put x1=; put y=; put z=; put lz=; put z1=; put lz1=; put m=; put m1=; run;x=abcdaba x1=cd y=kcdka z=cd a lz=5 z1=cd a lz1=5 m=cda m1=cda |
CopyRight 2018-2019 实验室设备网 版权所有 |